package com.mvp.shq.washer.http;

import com.mvp.shq.washer.entity.result.AlipayResult;
import com.mvp.shq.washer.entity.result.BaseResult;
import com.mvp.shq.washer.entity.result.WxPayResult;
import com.mvp.shq.washer.entity.shop.AddressData;
import com.mvp.shq.washer.entity.shop.Brand;
import com.mvp.shq.washer.entity.shop.Category;
import com.mvp.shq.washer.entity.shop.CollectResponse;
import com.mvp.shq.washer.entity.shop.CommentEntity;
import com.mvp.shq.washer.entity.shop.CommentResponse;
import com.mvp.shq.washer.entity.shop.MyOrderRestult;
import com.mvp.shq.washer.entity.shop.Product;
import com.mvp.shq.washer.entity.shop.ProductComment;
import com.mvp.shq.washer.entity.shop.ShopBanner;
import com.mvp.shq.washer.entity.shop.ShopSpec;
import com.mvp.shq.washer.entity.shop.TotalOrderData;
import com.mvp.shq.washer.entity.shop.UserCountInfo;
import com.mvp.shq.washer.entity.shop.address.AreaData;
import com.mvp.shq.washer.entity.shop.address.CityData;
import com.mvp.shq.washer.entity.shop.address.ProvinceData;
import com.mvp.shq.washer.entity.shop.address.UnitData;
import com.mvp.shq.washer.entity.shop.result.AddressResult;
import com.mvp.shq.washer.entity.shop.result.CollectResult;
import com.mvp.shq.washer.entity.shop.result.CommentResult;
import com.mvp.shq.washer.entity.shop.result.OrderDataListResult;
import com.mvp.shq.washer.entity.shop.result.OrderDataResult;
import com.mvp.shq.washer.entity.shop.result.OrderResult;
import com.mvp.shq.washer.entity.shop.result.ProductResult;
import com.mvp.shq.washer.entity.shop.result.ShopAliPayResult;

import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.RequestBody;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.PartMap;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;

/**
 * Created by shq1 on 2017/9/29.
 */

public interface ShopApiService {
    /**
     * 获取首页推荐SPU
     * @return
     */
    @GET("m/ecProduct/getHotSpu/anon")
    Observable<BaseResult<ProductResult>> getRecommentProduct();
    /**
     * 获取首页热门商品
     * @return
     */
    @GET("m/ecProduct/getHotSku/anon")
    Observable<BaseResult<ProductResult>> getHotProduct();

    /**
     * 获取商品详情
     * @param productId
     * @return
     */
    @GET("m/ecProduct/detail/anon")
    Observable<BaseResult<Product>> getProductInfo(@Query("userId")String userId,@Query("productId")String productId);

    /**
     * 获取省 列表信息
     * @param token
     * @return
     */
    @POST("m/area/findProvince")
    Observable<BaseResult<List<ProvinceData>>> getProvince(@Header("Authorization") String token);

    /**
     *根据省获取城市数据
     * @param token
     * @param provinceId
     * @return
     */
    @POST("m/area/findCityByProvince")
    Observable<BaseResult<List<CityData>>> getCitysByProvince(@Header("Authorization") String token,@Query("provinceId")String provinceId);

    /**
     * 根据城市获取地区数据
     * @param token
     * @param cityId
     * @return
     */
    @POST("m/area/findAreaByCity")
    Observable<BaseResult<List<AreaData>>> getAreasByCity(@Header("Authorization") String token,@Query("cityId")String cityId);

    /**
     * 根据地区获取单位数据
     * @param token
     * @param areaId
     * @return
     */
    @POST("m/area/findUnitByArea")
    Observable<BaseResult<List<UnitData>>> getUnitsByArea(@Header("Authorization") String token,@Query("areaId")String areaId);

    /**
     * 根据spu商品ID获取商品详情
     * @param unitId
     * @return
     */
    @GET("m/ecProduct/detailBySkuId/anon")
    Observable<BaseResult<Product>> getProductInfoBySku(@Query("userId")String userId,@Query("unitId")String unitId);

    /**
     * 根据规格属性获取商品信息
     * @param productId
     * @param attrIds
     * @return
     */
    @GET("m/ecProduct/getSkuByAttr/anon")
    Observable<BaseResult<Product>> getProductByAttr(@Query("productId")String productId,@Query("attrIds")String attrIds);

    /**
     * 新增或者修改收货地址
     * @param token
     * @param
     * @return
     */
    @POST("m/EcReceiveAddress/save")
    Observable<BaseResult<String>> addAddress(@Header("Authorization") String token,@Query("userId")String userId,@Query("id")String id, @Query("receiverPhone")String receiverPhone,@Query("receiverName")String receiverName,
                                              @Query("provinceId")String provinceId,@Query("provinceName")String provinceName,@Query("cityId")String cityId,@Query("cityName")String cityName,
                                              @Query("areaId")String areaId,@Query("areaName")String areaName,@Query("unitId")String unitId,@Query("unitName")String unitName,@Query("detailAddress")String detailAddress,@Query("status")String status);

    /**
     * 获取用户所有收货地址
     * @param token
     * @param userId
     * @return
     */
    @POST("m/EcReceiveAddress/findUserAddress")
    Observable<BaseResult<AddressResult>> getAllAddress(@Header("Authorization") String token,@Query("userId")String userId,@Query("pageNo")int pageNo,@Query("pageSize")int pageSize);

    /**
     * 设置默认地址
     * @param token
     * @param userId
     * @param ecReceiveAddressId
     * @return
     */
    @POST("m/EcReceiveAddress/setUserAddressDefault")
    Observable<BaseResult<String>> setDefAddress(@Header("Authorization") String token,@Query("userId")String userId,@Query("ecReceiveAddressId")String ecReceiveAddressId);

    /**
     * 删除收货地址
     * @param token
     * @param ecReceiveAddressId
     * @return
     */
    @POST("m/EcReceiveAddress/delete")
    Observable<BaseResult<String>> delAddress(@Header("Authorization") String token,@Query("ecReceiveAddressId")String ecReceiveAddressId);

    /**
     * 添加收藏
     * @param token
     * @param userId
     * @param productId
     * @return
     */
    @POST("m/ecCollect/save")
    Observable<BaseResult<String>> addCollect(@Header("Authorization") String token, @Query("userId")String userId, @Body List<CollectResponse> list);

    /**
     * 取消收藏
     * @param token
     * @param userId
     * @param productId
     * @return
     */
    @POST("m/ecCollect/delete")
    Observable<BaseResult<String>> delCollect(@Header("Authorization") String token,@Query("userId")String userId,@Query("productId")String productId);

    /**
     * 获取收藏列表
     * @param token
     * @param userId
     * @param pageSize
     * @param pageNo
     * @return
     */
    @POST("m/ecCollect/findListByUserId")
    Observable<BaseResult<CollectResult>> getCollectList(@Header("Authorization") String token, @Query("userId")String userId, @Query("pageNo")int pageNo, @Query("pageSize")int pageSize);

    /**
     * 获取分类
     * @return
     */
    @GET("m/ecCategory/nav/anon")
    Observable<BaseResult<List<Category>>> getCategory();

    /**
     * 获取品牌ID
     * @param categoryId
     * @return
     */
    @GET("m/ecCategory/brand/anon")
    Observable<BaseResult<List<Brand>>> getBrand(@Query("categoryId")String categoryId);


    /**
     * 获取默认地址
     * @param token
     * @param userId
     * @return
     */
    @POST("m/EcReceiveAddress/getDefaultAddress")
    Observable<BaseResult<AddressData>> getDefAddress(@Header("Authorization") String token,@Query("userId")String userId);

    /**
     * 提交订单
     * @param token
     * @param ecTotalOrderDto
     * @return
     */
    @POST("m/order/createOrder")
    Observable<BaseResult<OrderDataResult>> createOrder(@Header("Authorization") String token,@Body TotalOrderData ecTotalOrderDto);

    /**
     * 获取支付宝支付参数
     * @param token
     * @param orderNo
     * @param payType
     * @return
     */
    @POST("m/order/payOrder")
    Observable<BaseResult<ShopAliPayResult>> getAlipayResult(@Header("Authorization") String token, @Query("orderNo")String orderNo, @Query("payType")String payType);

    /**
     * 获取微信支付参数
     * @param token
     * @param orderNo
     * @param payType
     * @return
     */
    @POST("m/order/payOrder")
    Observable<BaseResult<WxPayResult>> getWXResult(@Header("Authorization") String token, @Query("orderNo")String orderNo, @Query("payType")String payType);

    /**
     * 根据分类Id获取规格数据
     * @param categoryId
     * @return
     */
    @GET("m/ecCategory/spec/anon")
    Observable<BaseResult<List<ShopSpec>>> getSpecByCategoryId(@Query("categoryId") String categoryId);

    /**
     * 获取商品sku列表
     * @param params
     * @return
     */
    @GET("m/ecProduct/getSkuList/anon")
    Observable<BaseResult<ProductResult>> getSkuList(@QueryMap Map<String,String> params,@Query("pageNo")int pageNo,@Query("pageSize")int pageSize);

    /**
     * 获取banner
     * @return
     */
    @GET("m/ecProduct/banner/anon")
    Observable<BaseResult<List<ShopBanner>>> getBanner();

    /**
     * 获取订单和收藏数量
     * @return
     */
    @POST("m/user/getMineInfo")
    Observable<BaseResult<UserCountInfo>> getUserCountInfo(@Header("Authorization") String token,@Query("userId")String userId);

    /**
     * 确认收货
     * @return
     */
    @POST("m/order/confirmGoods")
    Observable<BaseResult<String>> confirmGoods(@Header("Authorization") String token,@Query("userId")String userId,@Query("orderNo")String orderNo);

    /**
     * 获取订单详情
     * @return
     */
    @GET("m/order/getOrderDetail")
    Observable<BaseResult<OrderDataListResult>> getOrderDetail(@Header("Authorization") String token, @Query("userId")String userId, @Query("orderId")String orderId);


    /**
     * 获取商品评价列表
     * @param token
     * @param productId
     * @param pageNo
     * @param pageSize
     * @return
     */
    @POST("m/ecProductComment/findByProductId")
    Observable<BaseResult<CommentResult>> getCommentList(@Header("Authorization") String token, @Query("productId")String productId, @Query("pageNo")int pageNo, @Query("pageSize")int pageSize);

    /**
     * 获取我的订单列表
     * @param token
     * @param userId 用户Id
     * @param params 订单状态
     *               key=orderStatus,value=0
     *               0：未支付 1：待收货 2：待评价,全部订单不用传
     * @return
     */
    @GET("m/order/getOrders")
    Observable<BaseResult<MyOrderRestult>> getOrders(@Header("Authorization") String token, @Query("userId")String userId, @QueryMap Map<String,String> params,@Query("pageNo")int pageNo,@Query("pageSize")int pageSize);

    /**
     * 订单评价
     * @param token
     * @param list
     * @return
     */
    @POST("m/ecProductComment/insert")
    Observable<BaseResult<String>> productComment(@Header("Authorization") String token, @Body List<CommentEntity> list);

    /**
     * 提交退款申请
     * @param token
     * @param userId
     * @param orderId
     * @param receiveStatus
     * @param refundReason
     * @param maps
     * @return
     */
    @Multipart
    @POST("m/order/applyRefund")
    Observable<BaseResult<String>> submitRefund(@Header("Authorization") String token,@Query("userId")String userId,@Query("orderId")String orderId,@Query("receiveStatus")String receiveStatus,@Query("refundReason")String refundReason, @PartMap() Map<String, RequestBody> maps);

}
